
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;

using Swaf;
using Swaf.BizObj;
using Swaf.Container;

namespace Swaf.Script
{
	/// <summary>
	/// Summary description for ScriptContainerNode.
	/// </summary>
	public class ScriptContainerNode : MarshalByRefObject, INameAddressSupport, ICloneable
	{
		protected ScriptManager m_scriptMgr;
		protected string m_scriptLanguage;
		protected string m_getScriptName, m_setScriptName;
		protected string[] m_getParams, m_setParams;

		public ScriptContainerNode(ScriptManager mgr, string scriptLanguage, string getScriptName, string[] getParams, string setScriptName, string[] setParams)
		{
			m_scriptMgr = mgr;
			m_scriptLanguage = scriptLanguage;
			m_getScriptName = getScriptName;
			m_getParams = getParams;
			m_setScriptName = setScriptName;
			m_setParams = setParams;
		}

		public string[] Parameters {get{return m_getParams;}}

		#region INameAddressSupport Members
		public object get(string nameAddress, object oneArg)
		{
			return this.get(nameAddress, new object[]{oneArg});
		}

		public object get(string nameAddress)
		{
			return this.get(nameAddress, new object[]{});
		}

		public object get(string nameAddress, params object[] infoArgs)
		{
			return m_getScriptName == null?null:m_scriptMgr.invokeScriptFunction(m_scriptLanguage, m_getScriptName, infoArgs);
		}

		public bool isGetOnly {get{return false;}}

		public Swaf.Container.XmlSerializationSupport SerializationSupport
		{get{return XmlSerializationSupport.None;}}

		public string Xml{get{return null;}}

		public string getXml(string options) {return null;}

		public bool containsField(String nameAddress) {return false;}

		public void put(string nameAddress, object val)
		{
			put(nameAddress, val, null);
		}

		public void put(string nameAddress, object val, object extraInfo)
		{
			object[] info = val is object[] ? val as object[] : new object[] { val };
			if (m_setScriptName != null)
				m_scriptMgr.invokeScriptFunction(m_scriptLanguage, m_setScriptName, info);
		}
		#endregion

		#region ICloneable Members

		public object Clone()
		{
			return new ScriptContainerNode(m_scriptMgr, m_scriptLanguage, m_getScriptName, m_getParams, m_setScriptName, m_setParams);
		}

		#endregion
		public IEnumerator GetEnumerator() { return null; }
	}
}
